var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		pagId : 'paging',
		l_column : [ {
			colkey : "mId",
			name : "id",
			hide : true,
		}, {
			colkey : "mName",
			name : "用户名",
		}, {
			colkey : "mSex",
			name : "性别",
			renderData : function(rowindex,data, rowdata, column) {
				if(data==1){
					return '女';
				}else{
					return '男';
				}
			}
		}, {
			colkey : "mPhone",
			name:"用户电话",
		}, {
			colkey : "createTime",
			name : "创建时间",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd");
			}
		}],
		jsonUrl : rootPath + '/member/selectList',
		checkbox : true,
		checkValue : "mId"
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});
	$("#editMember").click("click", function() {
		editMember();
	});
	$("#deleteMember").click("click", function() {
		delMember();
	});
});
function editMember() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1) {
		layer.msg("只能选中一个");
		return;
	}
	pageii = layer.open({
		title : "编辑",
		type : 2,
		area : [ "500px", "50%" ],
		content : rootPath + '/member/addOrEdit?id=' + cbox
	});
}
function delMember() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/member/deleteEntity';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
}
